//
//  TempEffectExtension.swift
//  ANOA
//
//  Created by 邱仙凯 on 2023/7/12.
//  Copyright © 2023 zwb. All rights reserved.
//

import UIKit

extension ConfigMenuForm {
    // MARK:  主表影响处理
    // first 第一次处理显示数据，刚进来的时候，默认为否   刚进来需要触发所有影响但排除   setclear setClearDetails
    func setEffect(_ first:Bool = false) {
        TempLog("\n\n【主表影响开始】")

        for i in 0..<self.tempEffectM.count {
            let fieldNm = self.tempEffectM[i].field_nm.unwrap
            let value = any2Str(self.main[fieldNm])
            let oriValue = any2Str(self.oriMain[fieldNm])
            // 值变了
            if value != oriValue {
                TempLog("\(fieldNm)- 原值\(oriValue) - 新值\(value)，开始影响, first-\(first)")
                
                let eFFArr = self.tempEffectM[i].effectArr
                // 仅有一条且为空，则变化就产生影响
                if eFFArr.count == 1 , eFFArr.first!.field_value.unwrap == ""  {
                    startEffect(eFFArr.first!,first: first, newValue: value)
                } else {
               
                    var getEffect:TempEffectDet?
                     for eFOne in eFFArr {
                         if eFOne.field_value != EffectType.otherValue.rawValue {
                             
                             var condition = eFOne.condition.unwrap
                             if condition == "" {
                                 condition = "=="
                             }
                              let flagX = expressionVali(value + condition + eFOne.field_value.unwrap,rootTemp: rootTemp)
                               if flagX {
                                 TempLog(value + eFOne.field_value.unwrap)
                                 TempLog(flagX)
                                 getEffect = eFOne
                                 break
                             }
                         }
                    }
                    if getEffect.isSome {
                        // 等于什么就产生什么影响
                        TempLog("值为\(value),开始影响")
                        startEffect(getEffect!,first: first,newValue: value)
                    } else {
                        // 没有等于已配置的值     otherValue 则是除了已配置的其他类型都产生这个影响
                        let otArr = eFFArr.filter { $0.field_value == EffectType.otherValue.rawValue }
                        if otArr.count > 0 {
                            TempLog("值为otherValue,开始影响")
                            startEffect(otArr.first!,first: first,newValue: value)
                        }
                    }
                    
 
                    
//                    let fiArr = eFFArr.filter { $0.field_value == value }
//                    if fiArr.count > 0 {
//                        // 等于什么就产生什么影响
//                        startEffect(fiArr.first!,first: first, newValue: value)
//                    } else {
//                        // 没有等于已配置的值     otherValue 则是除了已配置的其他类型都产生这个影响
//                        let otArr = eFFArr.filter { $0.field_value == EffectType.otherValue.rawValue }
//                        if otArr.count > 0 {
//                            startEffect(otArr.first!,first: first, newValue: value)
//                        }
//                    }
                    
                }
                TempLog("\n")
            }
        }
        // newValue 是影响主体的新值  比如  新数字  影响别人为大写 需要 newValue
        func startEffect(_ item:TempEffectDet,first:Bool = false,newValue:String) {
            
            for i in 0..<item.grammarArr.count {
                let xxx = item.grammarArr[i]
                
                
                if !first {
                    // 第一次进来不能触发这些影响
                    
                    if xxx.keyword == EffectType.setClear.rawValue {
                        for i in 0..<xxx.contents.count {
                            let ddd = xxx.contents[i].removeBrackets
                            if ddd.contains("a.") {
                                let vvv = ddd.replacingOccurrences(of: "a.", with: "")
                                TempLog("主表\(vvv)被影响为 - 清空字段")
                                self.main[vvv] = ""
                            } else if ddd.contains("b.") {
                                
                                for i in 0..<self.detHandler[self.cDIndex].count {
                                    let vvv = ddd.replacingOccurrences(of: "b.", with: "")
                                    self.detHandler[self.cDIndex][i].dic[vvv] = ""
                                    TempLog("细表-\(vvv)被影响为 - 清空字段")
                                }
 
                            } else {
                                 TempLog("主表不带a.,默认主表\(ddd)被影响为 - 清空字段")
                                self.main[ddd] = ""
                            }
                        }
                    }
                    if xxx.keyword == EffectType.setClearDetails.rawValue {
                        if i != 0 {
                            KSToast("setClearDetails必须写在最前面")
                        }
                        TempLog("清空了细表")
                        
                        if self.rootTemp.multiDetailsTitles.count > 0 {
                            alertUtil(title: "联系管理员，3369", operateS: [nameAction(name: "确定", action: { _ in
                                
                            })])
                        } else {
                            self.detHandler[self.cDIndex] = [self.beginDetHandler[0]]
                            self.oriDetArr[self.cDIndex] = self.detHandler[self.cDIndex].compactMap{$0.dic}
                        }
                        
                        
                        
                    }
                }
                if xxx.keyword == EffectType.setFieldAnnotation.rawValue {
                    for i in 0..<xxx.contents.count {
                        let ddd = xxx.contents[i].removeBrackets
                        let pre = ddd.preChar(char: ":").unwrap
                        let suf = ddd.sufChar(char: ":").unwrap
                        if pre.contains("a.") {
                            KSToast("未接入影响a.,99")
                        } else  if pre.contains("b.") {
                            
                            if self.rootTemp.multiDetailsTitles.count > 0 {
                                alertUtil(title: "联系管理员，3362", operateS: [nameAction(name: "确定", action: { _ in
                                    
                                })])
                            } else {
                                for i in 0..<self.detHandler[0].count {
                                    let oneDet = self.detHandler[self.cDIndex][i]
                                    for xy in 0..<oneDet.temp.count {
                                        let fieldnm = self.detHandler[self.cDIndex][i].temp[xy].field_nm.unwrap
                                        let realK = pre.replacingOccurrences(of: "b.", with: "")
                                        if realK ==  fieldnm {
                                            TempLog("\(fieldnm)被影响为 - 设置字段名\(suf)")
                                            self.detHandler[self.cDIndex][i].temp[xy].field_annotation = suf
                                        }
                                    }
                                }
                                for xy in 0..<self.tempDet[0].count {
                                    let fieldnm = self.tempDet[0][xy].field_nm.unwrap
                                    let realK = pre.replacingOccurrences(of: "b.", with: "")
                                    if realK ==  fieldnm {
                                        TempLog("预备细表模板，\(fieldnm)被影响为 - 设置字段名\(suf)")
                                        self.tempDet[0][xy].field_annotation = suf
                                    }
                                }
                            }
                            
                            
                         
                            
                        } else {
                            
                            KSToast("未接入影响a.33")
                        }
                    }
                }
 
                if xxx.keyword == EffectType.setDicValue.rawValue {
                    for i in 0..<xxx.contents.count {
                      
                        let ddd = xxx.contents[i]
                        let pre = ddd.preChar(char: ":").unwrap
                        let suf = ddd.sufChar(char: ":").unwrap
                        if pre.contains("a.") {
                            let vvv = pre.replacingOccurrences(of: "a.", with: "")
                            let str = getDolVal(suf,main: self.main,rootTemp: rootTemp).0
                            self.main[vvv] = str
                             TempLog("主表-\(vvv)被影响为 - 赋值   \(str)")
                        } else  if pre.contains("b.") {
                            
                            for i in 0..<self.detHandler[self.cDIndex].count {
                                let vvv = pre.replacingOccurrences(of: "b.", with: "")
                                let str = getDolVal(suf,currDet: self.detHandler[self.cDIndex][i].dic,rootTemp: rootTemp).0
                                self.detHandler[self.cDIndex][i].dic[vvv] = str
                                TempLog("细表-\(vvv)被影响为 - 赋值   \(str)")
                            }
                            
                            
                        } else {
                            self.main[pre] = suf
                            TempLog("\(pre)被影响为 - 赋值   \(suf)")
                        }
                    }
                }
                if xxx.keyword == EffectType.setNumberCapital.rawValue {
                    for i in 0..<xxx.contents.count {
                        let ddd = xxx.contents[i].removeBrackets
                        if ddd.contains("a.") {
                            let vvv = ddd.replacingOccurrences(of: "a.", with: "")
                            TempLog("主表\(vvv)被影响为 - 数字大写")
                            
                            
                            self.main[vvv] = newValue.numberRMM()
                        }
                    }
                }
                
                
                if xxx.keyword == EffectType.setEnable.rawValue {
                    
                    let aDrr = xxx.contents.filter { $0.contains("a.") }
                    let reaDrr = aDrr.compactMap { $0.removeBrackets.replacingOccurrences(of: "a.", with: "") }
                    for yyy in 0..<self.mainHandler.count {
                        let temp = self.mainHandler[yyy].temp!
                        if isShowJ(temp,auCombine: self.tempAuditParamC,exType: self.excuteType) {
                            let tag = self.mainHandler[yyy].item!.tagx.unwrap
                            if reaDrr.contains(tag) {
                                TempLog("主表-\(tag)被影响为 - 可编辑")
                                self.mainHandler[yyy].temp?.isEditEnable = "1"
                                (self.mainHandler[yyy].item as! KSFormHItem).disabled = false
                            }
                        }
                        
                    }
                    mainEffectDetDealContains(xxx: xxx, effectType: xxx.keyword.unwrap)
                    
                    
                }
                if xxx.keyword == EffectType.setDisable.rawValue {
                    let aDrr = xxx.contents.filter { $0.contains("a.") }
                    let reaDrr = aDrr.compactMap { $0.removeBrackets.replacingOccurrences(of: "a.", with: "") }
                    for yyy in 0..<self.mainHandler.count {
                        let temp = self.mainHandler[yyy].temp!
                        if isShowJ(temp,auCombine: self.tempAuditParamC,exType: self.excuteType) {
                            let tag = self.mainHandler[yyy].item!.tagx.unwrap
                            if reaDrr.contains(tag) {
                                TempLog("主表-\(tag)被影响为 - 不可编辑")
                                self.mainHandler[yyy].temp?.isEditEnable = "0"
                                (self.mainHandler[yyy].item as! KSFormHItem).disabled = true
                            }
                        }
                        
                    }
                    
                    mainEffectDetDealContains(xxx: xxx, effectType: xxx.keyword.unwrap)
                }
                
                
                
                if xxx.keyword == EffectType.setLovUrl.rawValue ||
                    xxx.keyword == EffectType.setLovField.rawValue ||
                    xxx.keyword == EffectType.setMultichoice.rawValue ||
                    xxx.keyword == EffectType.setLovFieldBackfill.rawValue ||
                    xxx.keyword == EffectType.setSelectData.rawValue ||
                    xxx.keyword == EffectType.setComputedExpression.rawValue ||
                    xxx.keyword == EffectType.setSelectFieldBackfill.rawValue ||
                    xxx.keyword == EffectType.setFieldType.rawValue   {
                    
                    effectDealAssignment(xxx: xxx, effectType: xxx.keyword.unwrap)
                }
                
                
                
                if xxx.keyword == EffectType.setRequired.rawValue {
                    let aDrr = xxx.contents.filter { $0.contains("a.") }
                    let reaDrr = aDrr.compactMap { $0.removeBrackets.replacingOccurrences(of: "a.", with: "") }
                    for yyy in 0..<self.mainHandler.count {
                        let temp = self.mainHandler[yyy].temp!
                        if isShowJ(temp,auCombine: self.tempAuditParamC,exType: self.excuteType) {
                            let tag = self.mainHandler[yyy].item!.tagx.unwrap
                            if reaDrr.contains(tag) {
                                TempLog("主表-\(tag)被影响为 - 设置必填")
                                self.mainHandler[yyy].temp?.is_required = "1"
                                //                                (self.mainHandler[yyy].item as! KSFormHItem).setMustInput(true)
                            }
                        }
                        
                    }
                    mainEffectDetDealContains(xxx: xxx, effectType: xxx.keyword.unwrap)
                    
                    
                }
                if xxx.keyword == EffectType.setUnRequired.rawValue {
                    let aDrr = xxx.contents.filter { $0.contains("a.") }
                    let reaDrr = aDrr.compactMap { $0.removeBrackets.replacingOccurrences(of: "a.", with: "") }
                    for yyy in 0..<self.mainHandler.count {
                        let temp = self.mainHandler[yyy].temp!
                        if isShowJ(temp,auCombine: self.tempAuditParamC,exType: self.excuteType) {
                            let tag = self.mainHandler[yyy].item!.tagx.unwrap
                            if reaDrr.contains(tag) {
                                TempLog("主表-\(tag)被影响为 - 设置非必填")
                                self.mainHandler[yyy].temp?.is_required = "0"
                                //                                (self.mainHandler[yyy].item as! KSFormHItem).setMustInput(false)
                            }
                        }
                        
                        
                        
                    }
                    
                    mainEffectDetDealContains(xxx: xxx, effectType: xxx.keyword.unwrap)
                }
                if xxx.keyword == EffectType.setHidden.rawValue {
                    let aDrr = xxx.contents.filter { $0.contains("a.") }
                    let reaDrr = aDrr.compactMap { $0.removeBrackets.replacingOccurrences(of: "a.", with: "") }
                    
                    var rmItems = [FormItem]()
                    for yyy in 0..<self.mainHandler.count {
                        let temp = self.mainHandler[yyy].temp!
                        if isShowJ(temp,auCombine: self.tempAuditParamC,exType: self.excuteType) {
                            let tag = self.mainHandler[yyy].item!.tagx.unwrap
                            if reaDrr.contains(tag) {
                                rmItems.append(self.mainHandler[yyy].item!)
                                TempLog("\(tag)被影响为 - 隐藏")
                                self.mainHandler[yyy].temp?.isFormSHow = "0"
                            }
                        }
                        
                    }
                    
                    mainEffectDetDealContains(xxx: xxx, effectType: xxx.keyword.unwrap)
                }
                
                if xxx.keyword == EffectType.setShow.rawValue {
                    
                    let aDrr = xxx.contents.filter { $0.contains("a.") }
                    let reaDrr = aDrr.compactMap { $0.removeBrackets.replacingOccurrences(of: "a.", with: "") }
                    // 首先把模板的显示状态改了
                    for yyy in 0..<self.mainHandler.count {
                        let tag = self.mainHandler[yyy].item!.tagx.unwrap
                        if reaDrr.contains(tag) {
                            TempLog("\(tag)被影响为 - 显示")
                            self.mainHandler[yyy].temp?.isFormSHow = "1"
                        }
                    }
                    mainEffectDetDealContains(xxx: xxx, effectType: xxx.keyword.unwrap)
                    
                    
                    
                }
            }
           
            
            // 如果有显示隐藏的影响，需要重新布局
            let showHiddenArr = item.grammarArr.filter{  $0.keyword == EffectType.setShow.rawValue || $0.keyword == EffectType.setHidden.rawValue  }
            if showHiddenArr.count > 0 {
                bg.removeAllItem()
                self.showView()
                
                let xxxDH = self.detHandler[self.cDIndex]
                self.detHandler[self.cDIndex].removeAll()
                
                for i in 0..<xxxDH.count {
                    self.detHandler[self.cDIndex].appendAndCountH(xxxDH[i],auCombine: self.tempAuditParamC, exType: self.excuteType)
                }
             
            }
            
            
        }
    }
    
    // MARK:  细表影响处理
    func setDetEffect(_ first:Bool = false) -> Bool {
        TempLog("\n\n【细表影响开始】--------------")
        var effected = false // 被影响了吗 有影响再去算，省点资源
        
        for mm in 0..<self.detHandler.count {
            let dHmm = self.detHandler[mm]
            let effmm = self.tempEffectD[mm]
            for x in 0..<dHmm.count {
                for i in 0..<effmm.count {
                    
                    
                    
                    let fieldNm = effmm[i].field_nm.unwrap
                    
                    let value = any2Str(self.detHandler[mm][x].dic[fieldNm])
                    var oriValue:Any? = nil
                    if self.oriDetArr[mm].count > x {
                        oriValue = self.oriDetArr[mm][x][effmm[i].field_nm.unwrap]
                    }
                    

                    // 值变了
                    if value != any2Str(oriValue) {
                        effected = true
                        TempLog("-第\(x+1)条细表-\(fieldNm)-原值【\(any2Str(oriValue))】-新值【\(value)】")
                        TempLog("开始影响")
                        
                        
                        let eFFArr = effmm[i].effectArr
                        // 仅有一条且为空，则变化就产生影响
                        if eFFArr.count == 1 , eFFArr.first!.field_value.unwrap == ""  {
                            TempLog("变化就产生影响")
                            startDetEffect(eFFArr.first!,index: x,first: first)
                        } else {
                            
                            var getEffect:TempEffectDet?
                             for eFOne in eFFArr {
                                 if eFOne.field_value != EffectType.otherValue.rawValue {
                                     
                                     var condition = eFOne.condition.unwrap
                                     if condition == "" {
                                         condition = "=="
                                     }
                                      let flagX = expressionVali(value + condition + eFOne.field_value.unwrap,rootTemp: rootTemp)
                                     
                                      if flagX {
                                         TempLog(value + eFOne.field_value.unwrap)
                                         TempLog(flagX)
                                         getEffect = eFOne
                                         break
                                     }
                                 }
                            }
                            if getEffect.isSome {
                                // 等于什么就产生什么影响
                                TempLog("值为\(value),开始影响")
                                startDetEffect(getEffect!,index: x,first: first)
                            } else {
                                // 没有等于已配置的值     otherValue 则是除了已配置的其他类型都产生这个影响
                                let otArr = eFFArr.filter { $0.field_value == EffectType.otherValue.rawValue }
                                if otArr.count > 0 {
                                    TempLog("值为otherValue,开始影响")
                                    startDetEffect(otArr.first!,index: x,first: first)
                                }
                            }
     
                        }
                        
                        TempLog("\n")
                    }
                }
            }
        }
        

        return effected
        // 细表影响处理   detParam 细表参数值（多细表的时候使用）
        func startDetEffect(_ item:TempEffectDet,index:Int,first:Bool) {
            
            for xxx in item.grammarArr {
           
                if !first {
                    // 第一次进来不能触发这些影响
                    
                    // 清空某字段的值
                    if xxx.keyword == EffectType.setClear.rawValue {
                        for i in 0..<xxx.contents.count {
                            let ddd = xxx.contents[i].removeBrackets.sufChar(char: ".").unwrap
                       
                                 TempLog("\(ddd)被影响为 - 清空字段")
                                self.detHandler[self.cDIndex][index].dic[ddd] = ""
                            
                            
                        }
                    }
                }
                
                
                if xxx.keyword == EffectType.setClearDetails.rawValue {
                    KSToast("细表无法产生setClearDetails影响，配置出错")
                }
                
                
                if xxx.keyword == EffectType.setEnable.rawValue ||
                    xxx.keyword == EffectType.setDisable.rawValue ||
                    xxx.keyword == EffectType.setRequired.rawValue ||
                    xxx.keyword == EffectType.setUnRequired.rawValue ||
                    xxx.keyword == EffectType.setHidden.rawValue ||
                    xxx.keyword == EffectType.setShow.rawValue {
                    
                    detEffectDetDealContains(xxx: xxx, index: index, effectType: xxx.keyword.unwrap)
                    
                    
                }
                
                if xxx.keyword == EffectType.setDicValue.rawValue {
                    for i in 0..<xxx.contents.count {
                     
                        let ddd = xxx.contents[i]
                        let pre = ddd.preChar(char: ":").unwrap
                        let suf = ddd.sufChar(char: ":").unwrap
                        
                            let vvv = pre.sufChar(char: ".").unwrap
                            let str = getDolVal(suf,currDet: self.detHandler[self.cDIndex][index].dic,rootTemp: rootTemp).0

                            TempLog("\(vvv)被影响为 - 赋值\(str)")
                            self.detHandler[self.cDIndex][index].dic[vvv] = str
                        
                        
                    }
                }
                
                
                if xxx.keyword == EffectType.setLovUrl.rawValue {
                    
                    let preArr = xxx.contents.compactMap { $0.removeBrackets.preChar(char:"->") }
                    let sufArr = xxx.contents.compactMap { $0.removeBrackets.sufChar(char:"->") }
                    
                    for xy in 0..<self.detHandler[self.cDIndex][index].temp.count {
                        let fieldnm = self.detHandler[self.cDIndex][index].temp[xy].field_nm.unwrap
                        for im in 0..<preArr.count {
                            if preArr[im].contains(fieldnm) {
                                TempLog("\(fieldnm)被影响为 - 设置lov:\(sufArr[im])")
                                self.detHandler[self.cDIndex][index].temp[xy].setLovUrl(str: sufArr[im])
                            }
                        }
                    }
                }
                if xxx.keyword == EffectType.setLovField.rawValue {
                    
                    let preArr = xxx.contents.compactMap { $0.removeBrackets.preChar(char:"->") }
                    let sufArr = xxx.contents.compactMap { $0.removeBrackets.sufChar(char:"->") }
                    
                    for xy in 0..<self.detHandler[self.cDIndex][index].temp.count {
                        let fieldnm = self.detHandler[self.cDIndex][index].temp[xy].field_nm.unwrap
                        for im in 0..<preArr.count {
                            if preArr[im].contains(fieldnm) {
                                self.detHandler[self.cDIndex][index].temp[xy].setLovField(str: sufArr[im])
                            }
                        }
                    }
                }
                if xxx.keyword == EffectType.setLovFieldBackfill.rawValue {
                    
                    let preArr = xxx.contents.compactMap { $0.removeBrackets.preChar(char:"->") }
                    let sufArr = xxx.contents.compactMap { $0.removeBrackets.sufChar(char:"->") }
                    
                    for xy in 0..<self.detHandler[self.cDIndex][index].temp.count {
                        let fieldnm = self.detHandler[self.cDIndex][index].temp[xy].field_nm.unwrap
                        for im in 0..<preArr.count {
                            if preArr[im].contains(fieldnm) {
                                self.detHandler[self.cDIndex][index].temp[xy].setLovBackFill(str: sufArr[im])
                            }
                        }
                    }
                }
                if xxx.keyword == EffectType.setMultichoice.rawValue {
                    
                    let preArr = xxx.contents.compactMap { $0.removeBrackets.preChar(char:"->") }
                    let sufArr = xxx.contents.compactMap { $0.removeBrackets.sufChar(char:"->") }
                    
                    for xy in 0..<self.detHandler[self.cDIndex][index].temp.count {
                        let fieldnm = self.detHandler[self.cDIndex][index].temp[xy].field_nm.unwrap
                        for im in 0..<preArr.count {
                            if preArr[im].contains(fieldnm) {
                                TempLog("\(fieldnm)被影响为 - 设置多选值为:\(sufArr[im])")
                                self.detHandler[self.cDIndex][index].temp[xy].is_multichoice = sufArr[im]
                            }
                        }
                    }
                }
                
                // 改变计算公式
                if xxx.keyword == EffectType.setComputedExpression.rawValue {
                    
                    let preArr = xxx.contents.compactMap { $0.removeBrackets.preChar(char:"->") }
                    let sufArr = xxx.contents.compactMap { $0.removeBrackets.sufChar(char:"->") }
                    
                    for xy in 0..<self.detHandler[self.cDIndex][index].temp.count {
                        let fieldnm = self.detHandler[self.cDIndex][index].temp[xy].field_nm.unwrap
                        for im in 0..<preArr.count {
                            //  2025.10.17 需要验证字段 100%适配,避免出现像 z_unit1 匹配上了 z_unit 的情况, 影响了 z_unit 的计算
                            if preArr[im].contains(fieldnm), let currFieldNm = preArr[im].components(separatedBy: ".").last, currFieldNm == fieldnm {
                                TempLog("\(fieldnm)被影响为 - 设置计算表达式:\(sufArr[im])")
                                
                                self.detHandler[self.cDIndex][index].temp[xy].computed_expression = sufArr[im]
                            }
                        }
                    }
                }
            }
        }
    }
    
    
    // 统一处理赋值型的 影响  带  ->的
    func effectDealAssignment(xxx:GrammarModel,effectType:String) {
        
        let aDrr = xxx.contents.filter { $0.contains("a.") }
        let preArr = aDrr.compactMap { $0.removeBrackets.preChar(char:"->") }
        let sufArr = aDrr.compactMap { $0.removeBrackets.sufChar(char:"->") }
        
        for yyy in 0..<self.mainHandler.count {
            let temp = self.mainHandler[yyy].temp!
            let itemx = self.mainHandler[yyy]
            let tag = itemx.item!.tagx.unwrap
            for im in 0..<preArr.count {
                if preArr[im].contains(tag) {
                    if effectType == EffectType.setLovField.rawValue {
                        TempLog("主表-\(tag)被影响为 - 设置lov显示：\(sufArr[im])")
                        self.mainHandler[yyy].temp?.setLovField(str: sufArr[im])
                    }
                    if effectType == EffectType.setFieldType.rawValue {
                        TempLog("主表-\(tag)被影响为 - 设置字段类型：\(sufArr[im])")
                        self.mainHandler[yyy].temp?.field_type = sufArr[im]
                    }
                    if effectType == EffectType.setLovUrl.rawValue {
                        TempLog("主表-\(tag)被影响为 - 设置lovUrl：\(sufArr[im])")
                        self.mainHandler[yyy].temp?.setLovUrl(str: sufArr[im])
                    }
                    if effectType == EffectType.setLovFieldBackfill.rawValue {
                        TempLog("主表-\(tag)被影响为 - setLovBackFill：\(sufArr[im])")
                        self.mainHandler[yyy].temp?.setLovBackFill(str: sufArr[im])
                    }
                    if effectType == EffectType.setMultichoice.rawValue {
                        TempLog("主表-\(tag)被影响为 - 设置多选值：\(sufArr[im])")
                        self.mainHandler[yyy].temp?.is_multichoice = sufArr[im]
                    }
                    if effectType == EffectType.setSelectData.rawValue {
                        TempLog("主表-\(tag)被影响为 - setSelectData：\(sufArr[im])")
                        self.mainHandler[yyy].temp?.select_data = sufArr[im]
                    }
                    if effectType == EffectType.setSelectFieldBackfill.rawValue {
                        TempLog("主表-\(tag)被影响为 - setSelectFieldBackfill：\(sufArr[im])")
                        self.mainHandler[yyy].temp?.select_field_backfill = sufArr[im]
                    }
                    if effectType == EffectType.setComputedExpression.rawValue  {
                        TempLog("主表-\(tag)被影响为 - 改变计算公式:\(sufArr[im])")
                        self.mainHandler[yyy].temp?.computed_expression = sufArr[im]
                    }
                }
            }
            
        }
        
//        let bDrr = xxx.contents.filter { !$0.contains("a.") }
//        if bDrr.count > 0 {
//            KSToast("b.该影响未配置,987")
//        }
        
        
        
        
    }
    
    
    // 主表影响细表     具体影响的处理:  （包含式）    影响到当前多条细表和  预备细表模板
    // 主表 影响 细表
    func mainEffectDetDealContains(xxx:GrammarModel,effectType:String) {
        
        let bDrr = xxx.contents.filter { $0.contains("b.") }
        if bDrr.count > 0 {
            
            if self.rootTemp.multiDetailsTitles.count > 0 {
                alertUtil(title: "联系管理员，3363", operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
            } else {
                let reaDrr = bDrr.compactMap { $0.removeBrackets.replacingOccurrences(of: "b.", with: "") }
                for i in 0..<self.detHandler[self.cDIndex].count {
                    let oneDet = self.detHandler[self.cDIndex][i]
                    for xy in 0..<oneDet.temp.count {
                        let fieldnm = self.detHandler[self.cDIndex][i].temp[xy].field_nm.unwrap
                        if reaDrr.contains(fieldnm) {
                            
                            if effectType == EffectType.setEnable.rawValue {
                                TempLog("细表-\(fieldnm)被影响为 - 可编辑")
                                self.detHandler[self.cDIndex][i].temp[xy].isEditEnable = "1"
                                self.tempDet[0][xy].isEditEnable = "1"
                            }
                            if effectType == EffectType.setDisable.rawValue {
                                TempLog("细表-\(fieldnm)被影响为 - 不可编辑")
                                self.detHandler[self.cDIndex][i].temp[xy].isEditEnable = "0"
                                self.tempDet[0][xy].isEditEnable = "0"
                            }
                            if effectType == EffectType.setRequired.rawValue {
                                TempLog("细表-\(fieldnm)被影响为 - 必填")
                                self.detHandler[self.cDIndex][i].temp[xy].is_required = "1"
                                self.tempDet[0][xy].is_required = "1"
                            }
                            if effectType == EffectType.setUnRequired.rawValue {
                                TempLog("细表-\(fieldnm)被影响为 - 非必填")
                                self.detHandler[self.cDIndex][i].temp[xy].is_required = "0"
                                self.tempDet[0][xy].is_required = "0"
                            }
                            if effectType == EffectType.setShow.rawValue {
                                TempLog("细表-\(fieldnm)被影响为 - 显示")
                                self.detHandler[self.cDIndex][i].temp[xy].isFormSHow = "1"
                                self.tempDet[0][xy].isFormSHow = "1"
                            }
                            if effectType == EffectType.setHidden.rawValue {
                                TempLog("细表-\(fieldnm)被影响为 - 隐藏")
                                self.detHandler[self.cDIndex][i].temp[xy].isFormSHow = "0"
                                self.tempDet[0][xy].isFormSHow = "0"
                            }
                        }
                    }
                }
            }
            

            
        }
        
        
    }
    // 细表 影响 细表
    // xxx 单条影响模板   index 细表索引  effectType 影响类型  仅影响自己，不影响基础模板
    func detEffectDetDealContains(xxx:GrammarModel,index:Int,effectType:String) {
        
        
        let bDrr = xxx.contents
        let reaDrr = bDrr.compactMap { $0.removeBrackets.sufChar(char: ".").unwrap }
        
        for xy in 0..<self.detHandler[self.cDIndex][index].temp.count {
            let fieldnm = self.detHandler[self.cDIndex][index].temp[xy].field_nm.unwrap
            if reaDrr.contains(fieldnm) {
                
                if effectType == EffectType.setEnable.rawValue {
                    TempLog("细表-\(fieldnm)被影响为 - 可编辑")
                    self.detHandler[self.cDIndex][index].temp[xy].isEditEnable = "1"
                }
                if effectType == EffectType.setDisable.rawValue {
                    TempLog("细表-\(fieldnm)被影响为 - 不可编辑")
                    self.detHandler[self.cDIndex][index].temp[xy].isEditEnable = "0"
                }
                
                if xxx.keyword == EffectType.setRequired.rawValue {
                    TempLog("细表-\(fieldnm)被影响为 - 必填")
                    self.detHandler[self.cDIndex][index].temp[xy].is_required = "1"
                    
                }
                if xxx.keyword == EffectType.setUnRequired.rawValue {
                    TempLog("细表-\(fieldnm)被影响为 - 非必填")
                    self.detHandler[self.cDIndex][index].temp[xy].is_required = "0"
                    
                }
                if xxx.keyword == EffectType.setHidden.rawValue {
                    TempLog("细表-\(fieldnm)被影响为 - 非必填")
                    self.detHandler[self.cDIndex][index].temp[xy].isFormSHow = "0"
                    
                }
                if xxx.keyword == EffectType.setShow.rawValue {
                    TempLog("细表-\(fieldnm)被影响为 - 非必填")
                    self.detHandler[self.cDIndex][index].temp[xy].isFormSHow = "1"

                }
            }
        }
        
    }
}
